<?php
	session_start();
	
	function create_image()
	{
		if(isset($_SESSION["count"]))
		{
			$_SESSION["count"] = $_SESSION["count"] + 1;
		}
		else
		{
			$_SESSION["count"] = 1;
		}
		
		$md5 = md5(rand(0,999));
		$key_num = rand(0, 24);
		$security_code = substr($md5,$key_num,8);
		$_SESSION['security_code'] = $security_code;
		$bgs = array("bg1.png","bg2.png","bg3.png","bg4.png","bg5.png");
		$background = array_rand($bgs,1);
		$image = imagecreatefrompng($bgs[$background]);
		$white = imagecolorallocate($image,255,255,255);
		imagestring($image,5,15,6,$security_code,$white);
		header("Content-Type: image/jpeg");
		$m = $_SESSION["count"]%2;
		if($m == 1)
		{
			imagejpeg($image,"code1.jpg");
		}
		else
		{
			imagejpeg($image,"code0.jpg");
		}
		
		imagedestroy($image);
		echo $m;
		
	}
	create_image();
	exit();
?>